<template>
  <div class="">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <h2 style="font-weight: bold">基本信息</h2>
      </div>
      <div
        class="text item"
        style="display: flex;justify-content:space-between;width:90%;margin:0 auto;"
      >
        <div class="" style="width: 50%">
          <div>
            消息名称 <span style="margin-left: 20px">{{ listData.name }}</span>
          </div>
          <div class="m_top">
            消息类型
            <span style="margin-left: 20px">{{
              listData.messageTemplateAliasEnumDesc
            }}</span>
          </div>
          <div class="m_top">
            消息ID <span style="margin-left: 20px">{{ listData.id }}</span>
          </div>
          <div class="m_top">
            发送状态
            <span style="margin-left: 20px">{{ listData.sendStatusDesc }}</span>
          </div>
        </div>
        <div>
          <div class="m_top">
            发送用户
            <span style="margin-left: 20px">{{
              listData.sendUser || '暂无数据'
            }}</span>
            <!-- <el-button
              style="margin-left: 10px"
              type="success"
              @click="downExcel"
              v-if="listData.sendUser == '指定EXCEL导入学员'"
              >下载excel</el-button
            > -->
          </div>
          <div class="m_top">
            发送渠道
            <span style="margin-left: 20px">{{ basicInfo }}</span>
          </div>
          <div class="m_top">
            创建时间
            <span style="margin-left: 20px">{{ listData.createdTime }}</span>
          </div>
          <div class="m_top">
            发送时间<span
              style="margin-left: 20px"
              v-if="
                listData.messageTemplateAlias == 'TARGETED_MESSAGE_TEMPLATE'
              "
              >{{ listData.sendTime || '暂无数据' }}</span
            >
            <span
              style="margin-left: 20px"
              v-if="
                listData.messageTemplateAlias ==
                  'PERIOD_OF_SERVICE_MESSAGE_TEMPLATE'
              "
              >{{ listData.runTime }}</span
            >
          </div>
        </div>
      </div>
    </el-card>
    <el-card class="box-card">
      <div slot="header" style="display:flex;justify-content:space-between">
        <h2 style="font-weight: bold">发送数据</h2>
        <el-button
          class="box-card__div__button"
          type="success"
          @click="downFileExcel"
          >下载短信发送失败用户</el-button
        >
      </div>
      <div class="text item">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column
            align="center"
            prop="sendTypeDesc"
            label="发送渠道"
            width="180"
          >
          </el-table-column>
          <el-table-column align="center" prop="totalNum" label="发送数量">
          </el-table-column>
          <el-table-column
            align="center"
            prop="successNum"
            label="发送成功数量"
          >
          </el-table-column>
          <el-table-column align="center" prop="readNum" label="查看数量">
          </el-table-column>
          <el-table-column
            align="center"
            prop="subsequentNum"
            label="后续操作数量"
          >
          </el-table-column>
        </el-table>
      </div>
    </el-card>
  </div>
</template>

<script>
// 字典公共方法
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { messageDetail, messagesDetailsNumber } from '@/api/notice'
import { downFile } from '@utils/msgPublic'
export default {
  data() {
    return {
      listData: {},
      tableData: [],
      dataStatus: [],
      basicInfo: ''
    }
  },
  created() {},
  mounted() {
    this.getList()
    this.getDetails()
    this.getStatusList()
  },
  methods: {
    downExcel() {
      let id = this.listData.id
      let url = `/messages/tasks/${id}/details/ids/download`
      this.msgDown('get', url, '', '学员excel')
    },
    async downFileExcel() {
      let id = this.listData.id
      let url = `/messages/${id}/export`
      this.msgDown('get', url, '', '失败数据excel')
    },
    // 从字典中取到用户类型和发送状态
    async getStatusList(val) {
      this.dataStatus = await sysNormalDisable('send_status', 'send_status')
    },
    // 列表
    getList() {
      let id = this.$route.query.id
      let params = {}
      messageDetail(
        id,
        params,
        (res) => {
          this.listData = res
          this.basicInfo = this.listData.messageChannels
            .map((item) => {
              return item.sendTypeDesc
            })
            .join(',')
        },
        (err) => {
          this.$message({ message: err.message, type: 'warning' })
        }
      )
    },
    getDetails() {
      let id = this.$route.query.id
      let params = { templateTypeEnum: 'OPERATION_TEMPLATE' }
      messagesDetailsNumber(
        id,
        params,
        (res) => {
          res.forEach((ele) => {
            if (ele.readNum === null) {
              ele.readNum = '-'
            }
            if (ele.subsequentNum === null) {
              ele.subsequentNum = '-'
            }
          })
          this.tableData = res
        },
        (err) => {
          console.log('err===>', err)
        }
      )
    }
  }
}
</script>

<style lang="less" scoped>
.font_20 {
  font-size: 20px;
}
.m_top {
  margin-top: 20px;
}
.box-card .box-card__div {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  &__button {
    padding-left: 10px;
    width: 200px;
  }
}
</style>
